-
MGLSourceis an abstract base class for map content sources. A map content source supplies content to be shown on the map. A source is added to anMGLStyleobject along with anMGLForegroundStyleLayerobject. The foreground style layer defines the appearance of any content supplied by the source.Each source defined by the style JSON file is represented at runtime by an
MGLSourceobject that you can use to refine the map’s content. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]and-[MGLStyle sourceWithIdentifier:].Create instances of
See moreMGLShapeSourceand the concrete subclasses ofMGLTileSource(MGLVectorSourceandMGLRasterSource) in order to useMGLSource‘s properties and methods. Do not create instances ofMGLSourcedirectly, and do not create your own subclasses of this class.Declaration
Objective-C
@interface MGLSource : NSObjectSwift
class MGLSource : NSObject
-
MGLTileSourceis a map content source that supplies map tiles to be shown on the map. The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification. A tile source is added to anMGLStyleobject along with one or moreMGLRasterStyleLayerorMGLVectorStyleLayerobjects. Use a style layer to control the appearance of content supplied by the tile source.A tile source is also known as a tile set. To learn about the structure of a Mapbox-hosted tile set, view it in Mapbox Studio’s Tilesets editor.
Create instances of
See moreMGLRasterSourceandMGLVectorSourcein order to useMGLTileSource‘s properties and methods. Do not create instances ofMGLTileSourcedirectly, and do not create your own subclasses of this class.
-
MGLShapeSourceis a map content source that supplies vector shapes to be shown on the map. The shapes may be instances ofMGLShapeorMGLFeature, or they may be defined by local or external GeoJSON code. A shape source is added to anMGLStyleobject along with anMGLVectorStyleLayerobject. The vector style layer defines the appearance of any content supplied by the shape source.Each
geojsonsource defined by the style JSON file is represented at runtime by anMGLShapeSourceobject that you can use to refine the map’s content and initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]and-[MGLStyle sourceWithIdentifier:].Any vector style layer initialized with a shape source should have a
nilvalue in itssourceLayerIdentifierproperty.Example
See morevar coordinates: [CLLocationCoordinate2D] = [ CLLocationCoordinate2D(latitude: 37.77, longitude: -122.42), CLLocationCoordinate2D(latitude: 38.91, longitude: -77.04), ] let polyline = MGLPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count)) let source = MGLShapeSource(identifier: "lines", features: [polyline], options: nil) mapView.style?.addSource(source)
-
MGLRasterSourceis a map content source that supplies raster image tiles to be shown on the map. The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification. A raster source is added to anMGLStyleobject along with one or moreMGLRasterStyleLayerobjects. Use a raster style layer to control the appearance of content supplied by the raster source.Each
rastersource defined by the style JSON file is represented at runtime by anMGLRasterSourceobject that you can use to initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]and-[MGLStyle sourceWithIdentifier:].Example
See morelet source = MGLRasterSource(identifier: "clouds", tileURLTemplates: ["https://example.com/raster-tiles/{z}/{x}/{y}.png"], options: [ .minimumZoomLevel: 9, .maximumZoomLevel: 16, .tileSize: 512, .attributionInfos: [ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) ] ]) mapView.style?.addSource(source)Declaration
Objective-C
@interface MGLRasterSource : MGLTileSourceSwift
class MGLRasterSource : MGLTileSource
-
MGLVectorSourceis a map content source that supplies tiled vector data in Mapbox Vector Tile format to be shown on the map. The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification. A vector source is added to anMGLStyleobject along with one or moreMGLVectorStyleLayerobjects. A vector style layer defines the appearance of any content supplied by the vector source.Each
vectorsource defined by the style JSON file is represented at runtime by anMGLVectorSourceobject that you can use to initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]and-[MGLStyle sourceWithIdentifier:].Within each vector tile, each geometric coordinate must lie between −1 × extent and (extent × 2) − 1, inclusive. Any vector style layer initialized with a vector source must have a non-
nilvalue in itssourceLayerIdentifierproperty.Commonly used vector sources include Mapbox Streets, Mapbox Terrain, and Mapbox Traffic.
Example
See morelet source = MGLVectorSource(identifier: "pois", tileURLTemplates: ["https://example.com/vector-tiles/{z}/{x}/{y}.mvt"], options: [ .minimumZoomLevel: 9, .maximumZoomLevel: 16, .attributionInfos: [ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) ] ]) mapView.style?.addSource(source)Declaration
Objective-C
@interface MGLVectorSource : MGLTileSourceSwift
class MGLVectorSource : MGLTileSource
Install in Dash
Content Sources Reference